﻿#region Imports
using System;
using CommonUtilities.Extensions;
#endregion

namespace CommonUtilities.Attributes
{
    /// <summary>
    /// Specifies a friendly name for enum members
    /// </summary>
    [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
    public sealed class FriendlyNameAttribute : Attribute
    {
        #region Declaration
        /// <summary>
        /// Default property name
        /// </summary>
        public static readonly string DefaultPropertyName = "FriendlyName";

        /// <summary>
        /// Specifies the default instance for the <code>CommonUtilities.Attributes.FriendlyNameAttribute</code>
        /// </summary>
        public static readonly FriendlyNameAttribute Default = new FriendlyNameAttribute("FriendlyName cannot be blank."); // RKD indecisive
        #endregion

        #region Properties
        /// <summary>
        /// Friendly name for enum members
        /// </summary>
        public string FriendlyName { get; private set; }
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new default instance of <code>CommonUtilities.Attributes.FriendlyNameAttribute</code>
        /// </summary>
        internal FriendlyNameAttribute()
            : base()
        {

        }

        /// <summary>
        /// Initializes a new instance of <code>CommonUtilities.Attributes.FriendlyNameAttribute</code>
        /// with the specified friendly name &quot;<paramref name="friendlyName"/>&quot;
        /// </summary>
        /// <param name="friendlyName">Friendly name for enum members</param>
        public FriendlyNameAttribute(string friendlyName)
            : this()
        {
            if (friendlyName.IsNullOrEmpty()) throw new InvalidOperationException("FriendlyName cannot be blank.");
            else
                FriendlyName = friendlyName;
        }
        #endregion

        #region Methods
        public override bool Equals(object obj)
        {
            return this.FriendlyName == ((FriendlyNameAttribute)obj).FriendlyName;
        }

        /// <summary>
        /// Determines if this attribute is the default instance
        /// </summary>
        /// <returns>TRUE if the attribute is the default instance for this attribute class;
        /// <para>otherwise, FALSE</para></returns>
        public override bool IsDefaultAttribute()
        {
            return this.FriendlyName == Default.FriendlyName;
        }
        #endregion
    }
}
